from models.UserSubSysModels import Userclassifies,User,Expert
from utils.dataBase import db_session
from random import randint
#增加
def add():
    add= []
    addUser1 = User('name{}'.format(randint(0,10)),'123456',18200244217,'1290130117@qq.com',
                    'N', 1, 0)
    add.append(addUser1)
    addUser2 = User('name{}'.format(randint(0,10)),'123456',18200244217,'1290130117@qq.com',
                    'N', 1, 0)
    add.append(addUser2)
    addUser3 = User('name{}'.format(randint(0,10)),'123456',18200244217,'1290130117@qq.com',
                    'N', 1, 0)
    add.append(addUser3)
    addUser4 = User('name{}'.format(randint(0,10)),'123456',18200244217,'1290130117@qq.com',
                    'N', 1, 0)
    add.append(addUser4)

    addUserClassfiies1 = Userclassifies('专家{}'.format(randint(0,100)))
    add.append(addUserClassfiies1)
    addUserClassfiies2 = Userclassifies('专家{}'.format(randint(0,100)))
    add.append(addUserClassfiies2)
    addUserClassfiies3 = Userclassifies('专家{}'.format(randint(0,100)))
    add.append(addUserClassfiies3)
    addUserClassfiies4 = Userclassifies('专家{}'.format(randint(0,100)))
    add.append(addUserClassfiies4)

    addExpert1 = Expert('name{}'.format(randint(0,10)),'academic{}'.format(randint(0,10)),
                       'academic{}'.format(randint(0,10)))
    add.append(addExpert1)
    addExpert2= Expert('name{}'.format(randint(0,10)),'academic{}'.format(randint(0,10)),
                       'academic{}'.format(randint(0,10)))
    add.append(addExpert2)
    addExpert3 = Expert('name{}'.format(randint(0,10)),'academic{}'.format(randint(0,10)),
                       'academic{}'.format(randint(0,10)))
    add.append(addExpert3)
    addExpert4 = Expert('name{}'.format(randint(0,10)),'academic{}'.format(randint(0,10)),
                       'academic{}'.format(randint(0,10)))
    add.append(addExpert4)
    for i in add:
        print(i)
    db_session.add_all(add)
    db_session.commit()
#删除查询
def delete():
    delete = []
    users = User.query.all()
    print('删除：',users[0])
    db_session.delete(users[0])

    ucs = Userclassifies.query.all()
    print('删除:',ucs[0])
    db_session.delete(ucs[0])

    experts = Expert.query.all()
    print('删除',experts[0])
    db_session.delete(experts[0])
    db_session.commit()

#修改
def update():
    users = User.query.all()
    u2 = users[0]
    u2.username='修改'

    ucs = Userclassifies.query.all()
    uc2 = ucs[0]
    uc2.classname = '修改'

    experts = Expert.query.all()
    expert2 = experts[0]
    expert2.ename = '修改'
    db_session.commit()

"""
测试时间：2020.3.26
测试结果：全部通过
"""
if __name__ == '__main__':
    # add()
    # delete()
    update()